#ifndef SEARCH_ENGINE_H
#define SEARCH_ENGINE_H

#include <string>
#include <vector>
#include <map>
struct SearchResult {
    std::string title;
    std::string url;
    std::string description;
    double relevance_score;
};

class SearchEngine {
public:
    SearchEngine();
    ~SearchEngine();

    // Execute search
    std::vector<SearchResult> search(const std::string& query, int user_id = -1);
    
    // Set keyword weight
    bool setKeywordWeight(int user_id, const std::string& keyword, double weight);
    
    // Get keyword weight
    double getKeywordWeight(int user_id, const std::string& keyword);
    
    // Call Baidu search API
    std::vector<SearchResult> baiduSearch(const std::string& query);
    
    // Calculate search result relevance score
    double calculateRelevanceScore(const SearchResult& result, const std::string& query, 
                                  const std::map<std::string, double>& keyword_weights);

private:
    // HTTP request utility
    std::string makeHttpRequest(const std::string& url, const std::map<std::string, std::string>& headers = {});
    
    // Parse Baidu search results
    std::vector<SearchResult> parseBaiduResults(const std::string& response);
    
    // URL encoding
    std::string urlEncode(const std::string& str);
    
    // Extract keywords
    std::vector<std::string> extractKeywords(const std::string& query);
};

#endif // SEARCH_ENGINE_H